//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package 力扣.题库.未分类.demo1AND20;

public class demo12 {
    public demo12() {
    }

    public static void main(String[] args) {
        System.out.println(intToRoman(3749));
    }

    public static String intToRoman(int num) {
        String[][] roman = new String[][]{{"I", "V"}, {"X", "L"}, {"C", "D"}, {"M"}};
        StringBuilder sb = new StringBuilder();

        for(int romanIndex = 0; num != 0; num /= 10) {
            int numleft = num % 10;
            if (numleft >= 1 && numleft <= 3) {
                sb.append(roman[romanIndex][0].repeat(numleft));
            } else if (numleft == 4) {
                sb.append(roman[romanIndex][1]).append(roman[romanIndex][0]);
            } else if (numleft == 5) {
                sb.append(roman[romanIndex][1]);
            } else if (numleft >= 6 && numleft <= 8) {
                sb.append(roman[romanIndex][0].repeat(numleft - 5));
                sb.append(roman[romanIndex][1]);
            } else if (numleft == 9) {
                sb.append(roman[romanIndex + 1][0]);
                sb.append(roman[romanIndex][0]);
            }

            ++romanIndex;
        }

        return sb.reverse().toString();
    }
}
